﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using MvvmEx.Base;

namespace MvvmEx.Converter
{
    /// <summary>
    /// 调整TreeView的左边距
    /// </summary>
    public class TreeViewItemMarginConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var treeNode = value as TreeNodeViewModelBase;

            if (treeNode == null || parameter == null) return new Thickness(0, 0, 0, 0);

            var leftDistance = double.Parse(parameter.ToString());

            var left = leftDistance * treeNode.Level;

            var margin = new Thickness(left, 0, 0, 0);

            return margin;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return Binding.DoNothing;
        }
    }
}